package com.interview.javabase.algorithm;

/**
 * @author: zsg
 * @description: 选择排序 O(n) = n2
 * @date: 2019/8/25 11:31
 * @modified:
 */
public class selectSort {
    public static void main(String[] args) {
        Integer[] arr = new Integer[]{101, 34, 119, 1, -1, -2};
        for (int i = 0; i < arr.length - 1; i++) {

            for (int j = 0; j < arr.length - i - 1; j++) {
                if (arr[j] > arr[j + 1]) {
                    int tmp = arr[j];
                    arr[j] = arr[j + 1];
                    arr[j + 1] = tmp;
                }
            }

            for (int k = 0; k < arr.length; k++) {
                Integer integer = arr[k];
                System.out.print(integer + " ");
            }
            System.out.println();
        }

        for (int i = 0; i < arr.length; i++) {
            Integer integer = arr[i];
            System.out.print(integer + " ");
        }
    }
}
